Texture InputTexture;

float threshold = 0.75;
float4 color1 = {0.0,0.0,0.0,1.0};
float4 color2 = {1.0,1.0,1.0,1.0};

sampler inputTexture = sampler_state 
{ 
    texture = <InputTexture>; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter = LINEAR; 
};
 
struct VS_OUTPUT
{
	float4 Position	: POSITION;
	float2 TexCoords : TEXCOORD0;
};
 
float4 Threshold_PS (VS_OUTPUT Input) : COLOR0
{
	float4 color = tex2D(inputTexture, Input.TexCoords);
	float intensity = (color.r + color.g + color.b)/3.0;
	if(intensity <= threshold)
		return color1;
	else
		return color2;
}
 
technique Threshold
{
	pass P0
	{
		PixelShader = compile ps_2_0 Threshold_PS();
	}
}